$(() => {
    $.getJSON("/api/user/getCurrentUser", result => {
        console.log(result)
        let loginStatusStr = '';
        if (!result['data']) {
            // 获取用户成功
            loginStatusStr += `<a href="login.html" target="_blank">请登录</a>
                        <a href="register.html" target="_blank" class="style-red">免费注册</a>`
        } else {
            loginStatusStr += `
                ${result['data'].username}
                <a href="javascript:logoutfun();">注销</a>
            `
        }
        $('.shortcut>.w>.fl>ul>li:last-child').html(loginStatusStr)
    })
})

function logoutfun() {
    // console.log("注销")
    // if(confirm("确认注销当前用户吗")){
    //     $.getJSON("/api/user/logout",ret=>{
    //         console.log(ret)
    //         if(ret['code']==1010){
    //             window.location.href = '/login.html'
    //         }
    //     })
    // }
    let layer = layui.layer
    layer.confirm('确认注销当前用户吗？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        $.getJSON("/api/user/logout", ret => {
            layer.msg(ret['msg']);
            if (ret['code'] == 1010) {
                window.location.href = '/login.html'
            }
        })
    }, function () {
        layer.msg('操作取消');
    });
}